package hxy.scan.server.entity;

import lombok.Data;
import org.springframework.http.HttpStatus;


/**
 * @program erp-server
 * @description ${description}* @author eric* @date 2020/2/27
 */
@Data
public class BaseResponse<T> {
    String message;
    Integer code;
    T data;

    public BaseResponse() {

    }

    public BaseResponse(int code, String msg) {
        this.setCode(code);
        this.setMessage(msg);
    }

    public BaseResponse(int code, String msg, T data) {
        this.setCode(code);
        this.setMessage(msg);
        this.setData(data);
    }

    public static <T> BaseResponse<T> success() {
        return new BaseResponse<T>(HttpStatus.OK.value(), "成功", null);
    }

    public static <T> BaseResponse<T> success(T data) {
        return new BaseResponse<T>(HttpStatus.OK.value(), "成功", data);
    }

    public static <T> BaseResponse<T> success(String msg) {
        return new BaseResponse<T>(HttpStatus.OK.value(), msg, null);
    }

    public static <T> BaseResponse<T> success(String msg, T data) {
        return new BaseResponse<T>(HttpStatus.OK.value(), msg, data);
    }

    public static <T> BaseResponse<T> success(int code, String msg, T data) {
        return new BaseResponse<T>(code, msg, data);
    }

    public static <T> BaseResponse<T> error(T data) {
        return new BaseResponse<T>(HttpStatus.OK.value(), "失败", data);
    }

    public static <T> BaseResponse<T> error(String message) {
        return new BaseResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), message, null);
    }

    public static <T> BaseResponse<T> notFound(String message) {
        return new BaseResponse(HttpStatus.NOT_FOUND.value(), message, null);
    }

    public static <T> BaseResponse<?> error(String message, T data) {
        return new BaseResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), message, data);

    }

    public static <T> BaseResponse badrequest(String message) {
        return new BaseResponse(HttpStatus.BAD_REQUEST.value(), message, null);
    }

    public static <T> BaseResponse badrequest(String message, T data) {
        return new BaseResponse(HttpStatus.BAD_REQUEST.value(), message, data);
    }
}
